package com.sls.web.manager.action.recharge;

import java.util.List;

import javax.annotation.Resource;

import com.sls.web.manager.action.SuperAction;
import com.sls.web.manager.common.Constants;
import com.sls.web.manager.execption.ManagerException;
import com.sls.web.manager.recharge.pojo.Adjustment;
import com.sls.web.manager.recharge.pojo.Orders;
import com.sls.web.manager.recharge.service.AdmjustmentService;

public class AdjustmentAction extends SuperAction {
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	@Resource(name = "admjustmentService")
	private AdmjustmentService admjustmentService;
	private Orders order;
	private List<Orders> list;
	private Adjustment adj;

	public String index() {
		return "edit";
	}

	public String findOrder() throws Exception {
		try {
			if (order.getBuyer().length() != 11) {
				order.setId(order.getBuyer());
				order.setBuyer(null);
			}
			list = admjustmentService.findOreders(order, getCurrentOperator());
			return "edit";
		} catch (ManagerException e) {
			addActionError(e.getMessage());
			// throw e;
		}
		return null;
	}

	public String eto() throws Exception {

		adj.setType(true);
		adj.setStatus(Constants.WAIT_VERIFY);
		adj.setDeleted(false);
		try {
			admjustmentService.eto(adj, getCurrentOperator());
			redirectionUrl = "adjustment!index.htm";
			return "success";
		} catch (ManagerException e) {
			addActionError(e.getMessage());
			// throw e;
		}
		return "edit";
	}

	public String adjust() throws Exception {
		adj.setType(false);
		adj.setStatus(Constants.WAIT_VERIFY);
		adj.setDeleted(false);
		try {
			admjustmentService.eto(adj, getCurrentOperator());
			redirectionUrl = "adjustment!index.htm";
			return "success";
		} catch (ManagerException e) {
			addActionError(e.getMessage());
		}
		return "edit";

	}

	public Orders getOrder() {
		return order;
	}

	public void setOrder(Orders order) {
		this.order = order;
	}

	public List<Orders> getList() {
		return list;
	}

	public void setList(List<Orders> list) {
		this.list = list;
	}

	public void setAdj(Adjustment adj) {
		this.adj = adj;
	}

	public Adjustment getAdj() {
		return adj;
	}

}
